package com.xbongbong.pro.dataset.service.impl;


import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.dataset.service.DataSetChartExportService;
import com.xbongbong.pro.dataset.service.DataSetChartResultService;
import com.xbongbong.pro.statistic.abstracts.AbstractChartExport;
import com.xbongbong.pro.statistic.help.ChartExportHelp;
import com.xbongbong.pro.statistic.result.pojo.dto.ChartPenetrateResultDTO;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultVO;
import com.xbongbong.saas.constant.BasicConstant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 数据集图表导出操作
 *
 * @author zyy
 * @date 2022/11/24/ 13:55:00
 * @since v1.0
 */
@Service("dataSetChartExportService")
public class DataSetChartExportServiceImpl extends AbstractChartExport implements DataSetChartExportService {

    @Resource
    private DataSetChartResultService dataSetChartResultService;
    @Resource
    private ChartExportHelp chartExportHelp;

    @Override
    public void initExportConfig(ChartPenetrateResultDTO chartResultDTO) throws XbbException {
        //分页
        chartResultDTO.setPageSize(10000);
        chartResultDTO.setPage(BasicConstant.ONE);
    }

    @Override
    public ChartResultVO getBaseExportData(ChartPenetrateResultDTO chartResultDTO) throws XbbException {
        ChartResultVO chartResultVO;
        //判断是否不是穿透导出
        boolean isNotPenetrate = chartResultDTO.getPenetrateCondition() == null && "".equals(chartResultDTO.getSelectedAxis()) && "".equals(chartResultDTO.getSelectedLegend());
        //联动相关解析下放到渲染或穿透逻辑中处理
        if(isNotPenetrate){
            chartResultVO = dataSetChartResultService.chartResult(chartResultDTO);
        }else{
            chartExportHelp.replaceCharIdIn(chartResultDTO);
            chartResultVO = dataSetChartResultService.chartPenetrateResult(chartResultDTO);
        }
        return chartResultVO;
    }
}
